package com.gitee.gen.jpa;

import cn.shoukaiseki.reddragon.common.utils.ListUtils;

import java.util.List;

/**
 *
 **/
public class SksJpaParserJpaOption {

    //后缀关键字,按顺序
    private String[] keyword;

    //描述
    private String description;

    //备注
    private String remark;

    private String sample;


//https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#reference

    public static List<SksJpaParserJpaOption> japOptionList(){
        List<SksJpaParserJpaOption> jpaOptions = ListUtils.newArrayList(
                new SksJpaParserJpaOption().setKeyword("Customize")
                        .setDescription("自定义,将会忽略"),
//                , "NotNull" 避免字段名等原因,所有后缀采用单种关键字,选字符多的
                new SksJpaParserJpaOption().setKeyword("IsNotNull").setRemark("过滤值要传'1'才启用过滤"),
                //, "Null"
                new SksJpaParserJpaOption().setKeyword("IsNull").setRemark("过滤值要传'1'才启用过滤"),
                //"NotEmpty",
                new SksJpaParserJpaOption().setKeyword("IsNotEmpty").setDescription("如果不为空字符").setRemark("过滤值要传'1'才启用过滤"),
                //,"Empty"
                new SksJpaParserJpaOption().setKeyword("IsEmpty").setDescription("如果为空字符").setRemark("过滤值要传'1'才启用过滤"),
                new SksJpaParserJpaOption().setKeyword("FindInSet").setDescription("and FIND_IN_SET(#{autumnParams.userIdFindInSet},t1.userId)"),
                new SksJpaParserJpaOption().setKeyword("NotLike"),
                new SksJpaParserJpaOption().setKeyword("Like"),
                //,"Is"
                new SksJpaParserJpaOption().setKeyword("Equals"),
                new SksJpaParserJpaOption().setKeyword("Between"),
                new SksJpaParserJpaOption().setKeyword("StrRange").setDescription("字符串范围,json数组,2个元素,会格式化成 [第1个元素]>= and [第2个元素]<="),
                //,"Before"
                new SksJpaParserJpaOption().setKeyword("LessThan"),
                new SksJpaParserJpaOption().setKeyword("LessThanEqual"),
                new SksJpaParserJpaOption().setKeyword("GreaterZero").setDescription("如果大于0").setRemark("过滤值传'1'才启用过滤"),
                //,"After"
                new SksJpaParserJpaOption().setKeyword("GreaterThan"),
                new SksJpaParserJpaOption().setKeyword("GreaterThanEqual"),
                new SksJpaParserJpaOption().setKeyword("StartingWith"),
                new SksJpaParserJpaOption().setKeyword("EndingWith"),
                new SksJpaParserJpaOption().setKeyword("Containing"),
                new SksJpaParserJpaOption().setKeyword("NotIn"),
                new SksJpaParserJpaOption().setKeyword("Not"),
                new SksJpaParserJpaOption().setKeyword("In"),
                new SksJpaParserJpaOption().setKeyword("AndTrue")
                        .setDescription("位过滤,只显示对应位为1")
                        .setSample("and (bit_type & #{bitTypeAndTrue})=#{bitTypeAndTrue}"),
                new SksJpaParserJpaOption().setKeyword("AndFalse")
                        .setDescription("位过滤,只显示对应位为0的数据")
                        .setSample("and !(bit_type & #{bitTypeAndFalse})"),
                new SksJpaParserJpaOption().setKeyword("True"),
                new SksJpaParserJpaOption().setKeyword("False"),
                new SksJpaParserJpaOption().setKeyword("IgnoreCase")
                        .setSample("and UPPER(x.name) = UPPER(#{name})")
                        .setDescription("mysql 对大小写默认不敏感的,该功能基本无用,如需区分,需要查询前加 binary 关键字,如:  and binary x.name=#{name}")
                ,

                null
        );

        return (List<SksJpaParserJpaOption>) jpaOptions.stream().filter((item)->item!=null);
    }


    public String[] getKeyword() {
        return keyword;
    }

    public SksJpaParserJpaOption setKeyword(String... keyword) {
        this.keyword = keyword;
        return this;
    }

    public String getDescription() {
        return description;
    }

    public SksJpaParserJpaOption setDescription(String description) {
        this.description = description;
        return this;
    }

    public String getSample() {
        return sample;
    }

    public SksJpaParserJpaOption setSample(String sample) {
        this.sample = sample;
        return this;
    }

    public String getRemark() {
        return remark;
    }

    public SksJpaParserJpaOption setRemark(String remark) {
        this.remark = remark;
        return this;
    }
}
